<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE html>
<html>
  <head>
    <title>教材吧-完善用户信息</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<%@ include file="/base/jsp/includeweb.jsp"%>
    <link type="text/css" rel="stylesheet" href="${path}/base/css/user.css"/>
    <script src="http://qzonestyle.gtimg.cn/qzone/openapi/qc_loader.js" type="text/javascript" data-appid="1103761343" data-redirecturi="http://127.0.0.1:8080/bookshop/qc_callback.html" charset="utf-8"></script>
  </head>
  <body>
  <%@ include file="/base/jsp/header.jsp"%>
  <%@ include file="/base/jsp/search-header.jsp"%>
  <div id="content-wrapper" class="content-wrapper border-top-org clear">
  
    <div class="regist-wrapper">
        <form id="form1" name="form1" method="post" action="">
        
        <div class="regist-info-wrapper">
              <h3>完善用户信息</h3>
              <div>如果你已有教材吧账号，则<a href="weblogin.do" target="_blank">在此登录</a></div>
        </div>
        
        <div class="input-wrapper clear">
        <div class="input-wrapper-info">用户名：</div>
        <div class="input-wrapper-input"><input type="text" name="username" id="username" class="regist-input"/></div>
        <div class="input-wrapper-tip"></div>
        </div>
        
        <div class="input-wrapper clear">
        <div class="input-wrapper-info">邮箱：</div>
        <div class="input-wrapper-input" style="z-index:9000;"><input type="text" name="mail" id="mail" class="regist-input"/></div>
        <div class="input-wrapper-tip">邮箱用于找回密码</div>
        </div>
         
        <div class="input-wrapper clear">
        <div class="input-wrapper-info">选择学校：</div>
        <div class="input-wrapper-input z-index1"><ul id="regist-school-input" class="search-bottom-input"><span class="school-text">学校</span></ul></div>
        <div class="input-wrapper-tip"></div>
        </div>
        
        <div class="input-wrapper clear">
        <div class="input-wrapper-info">选择院系：</div>
        <div class="input-wrapper-input z-index2"><ul id="regist-depart-input" class="search-bottom-input"><span class="depart-text">院系</span></ul></div>
        <div class="input-wrapper-tip"></div>
        </div>
        
        <div class="input-wrapper clear">
        <div class="input-wrapper-info">专业：</div>
        <div class="input-wrapper-input z-index3"><ul id="regist-major-input" class="search-bottom-input"><span class="major-text">专业</span></ul></div>
        <div class="input-wrapper-tip"></div>
        </div>
        
        <div class="input-wrapper clear">
        <div class="input-wrapper-info">入学年份：</div>
        <div class="input-wrapper-input z-index4"><ul id="regist-time-input" class="search-bottom-input"><span class="time-text">入学年份</span></ul></div>
        <div class="input-wrapper-tip"></div>
        </div>
        
        <div class="input-wrapper-but"><input id="subBtn" type="button" value="提交信息" class="but-org" onclick="regist()"/></div>
      </form>
    </div>
    
  </div>
  <%@ include file="/base/jsp/footer.jsp"%>
  </body>
  <script type="text/javascript">
  var stip = "学校";
  var dtip = "院系";
  var mtip = "专业";
  var ttip = "入学年份";
  var id = getParameter("id");
  var usernameT = getParameter("username");
  var token = getParameter("token");
  $(function(){
     var date = new Date();
     var year = date.getFullYear();
     $("input[name=username]").val(usernameT)
     request("listSchool.do","pageIndex=0&pageSize=100&isNotPage=0",function(data){
                var d = data.data;
                $("#regist-school-input li").remove();
                for(var i =0 ; i < d.length; i++){
                    var rowd = $("<li></li>");
                    var dt = d[i];
                    rowd.attr("id",dt.id);
                    rowd.text(dt.name);
                    rowd.attr("code",dt.code);
                    $("#regist-school-input").append(rowd);
                }
                $("#regist-school-input li").click(function(){
                    var s = $(this);
                    s.parent().find("span").eq(0).text(s.text());
                    s.parent().find("span").eq(0).attr("id",s.attr("id"));
                    s.parent().find("span").eq(0).attr("code",s.attr("code"));
                    s.parent().find("li").hide();
                    //处理后续的院系和专业
                    $("#regist-depart-input li").remove();
                    $("#regist-depart-input").find("span").eq(0).text("院系");
                    $("#regist-depart-input").find("span").eq(0).attr("code","");
                    $("#regist-depart-input").find("span").eq(0).attr("id","");
                    //处理专业
                    $("#regist-major-input li").remove();
                    $("#regist-major-input").find("span").eq(0).text("专业");
                    $("#regist-major-input").find("span").eq(0).attr("code","");
                    $("#regist-major-input").find("span").eq(0).attr("id","");
                    //根据id再去请求院系列表
                    request("listDepartment.do","pageIndex=0&pageSize=100&isNotPage=0&pid="+$(this).attr("id"),function(data){
                        var dd = data.data;
                        for(var i in dd){
                           var dt = dd[i];
                           var rowd = $("<li></li>");
                           rowd.attr("id",dt.id);
                           rowd.text(dt.name);
                           rowd.attr("code",dt.code);
                           $("#regist-depart-input").append(rowd);
                        }
                        $("#regist-depart-input li").click(function(){
                            var s = $(this);
                            s.parent().find("span").eq(0).text(s.text());
                            s.parent().find("span").eq(0).attr("id",s.attr("id"));
                            s.parent().find("span").eq(0).attr("code",s.attr("code"));
                            s.parent().find("li").hide();
                            //处理专业
                            $("#regist-major-input li").remove();
                            $("#regist-major-input").find("span").eq(0).text("专业");
                            $("#regist-major-input").find("span").eq(0).attr("code","");
                            $("#regist-major-input").find("span").eq(0).attr("id","");
                            //获取专业列表
                            request("listMajor.do","pageIndex=0&pageSize=100&isNotPage=0&pid="+$(this).attr("id"),function(data){
                                var dd = data.data;
                                for(var i in dd){
                                   var dt = dd[i];
                                   var rowd = $("<li></li>");
                                   rowd.attr("id",dt.id);
                                   rowd.text(dt.name);
                                   rowd.attr("code",dt.code);
                                   $("#regist-major-input").append(rowd);
                                }
                                //专业列表的点击函数
                                 $("#regist-major-input li").click(function(){
                                       var s = $(this);
                                       s.parent().find("span").eq(0).text(s.text());
                                       s.parent().find("span").eq(0).attr("id",s.attr("id"));
                                       s.parent().find("span").eq(0).attr("code",s.attr("code"));
                                       s.parent().find("li").hide();
                                  });
                            });
                            //end of 获取专业列表
                        });
                    });  //end of 院系列表
              })
          });
      //设置年份
        for(var i = 0; i < 10 ;i++){
            var row=$("<li></li>")
            row.text(year-i);
            row.attr("code",(year-i)+"-01-01");
            $("#regist-time-input").append(row);
        }
        $("#regist-time-input li").click(function(){
            $(this).parent().find("span").text($(this).text());
            $(this).parent().find("span").attr("code",$(this).attr("code"));
            $(this).parent().find("li").hide();
        })
  })
  
  
  function regist(){
      var username = $("input[name=username]").val();
      var mail = $("input[name=mail]").val();
      var sid = $("#regist-school-input").find("span").attr("id");
      var sName = $("#regist-school-input").find("span").text();
      var sCode = $("#regist-school-input").find("span").attr("code");
      var dmid = $("#regist-depart-input").find("span").attr("id");
      var dmName = $("#regist-depart-input").find("span").text();
      var dmCode = $("#regist-depart-input").find("span").attr("code");
      var mjid = $("#regist-major-input").find("span").attr("id");
      var mjName = $("#regist-major-input").find("span").text();
      var mCode = $("#regist-major-input").find("span").attr("code");
       var entranceDate = $("#regist-time-input").find("span").attr("code");
      var pattern = /^[\w\._]+@[\w_]+\.[\w_\.]+$/;
      if(!isDefine(mail)||sName==stip||dmName==dtip||mjName==mtip||entranceDate==ttip){
          alert("请输入完整信息");
          return ;
      }else if(!pattern.test(mail)){
          alert("请输入正确的邮箱格式");
          return ;
      }
      var query = "id="+id+"&username="+username+"&mail="+mail;
      query +="&sid="+sid+"&sName="+sName+"&sCode="+sCode+"&dmid="+dmid+"&dmName="+dmName+"&dCode="+dmCode+"&mjid="+mjid+"&mjName="+mjName+"&mCode="+mCode+"&entranceDate="+$.formatDate("yyyy-MM-dd HH:mm:ss",entranceDate);
      request("saveUser.do",query,function(data){
          alert("信息完善成功!!");
           var query = "qqNumber="+token;
                  request("Mlogin.do",query,function(data){
                     username = data.username;
                     userid = data.id;
                     entranceYear = $.formatDate("yyyy",data.entranceDate);
                     var yearCode = getYearCode();
                     location.href="searchschool.do?school="+data.sName+"&scode="+data.sCode+"&depart="+data.dmName+"&dcode="+data.dCode+"&major="+data.mjName+"&mcode="+data.mCode+"&yearCode="+yearCode+"&sid="+data.sid+"&did="+data.dmid+"&mid="+data.mjid;
                  })
      })
  }
  </script>
</html>